package com.wus.gateway.config.filter;

import com.wus.common.core.account.AccountThreadLocal;
import com.wus.gateway.config.SaTokenConfigure;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @Description: 资源释放过滤器
 * @Author: wus
 * @Date: 2024/12/18 11:13
 */
@Component
public class ResourceReleaseFilter implements GlobalFilter, Ordered {

    private final Logger logger = LoggerFactory.getLogger(ResourceReleaseFilter.class);

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        logger.info("---------- ResourceReleaseFilter");
        // 进行AccountThreadLocal资源释放
        AccountThreadLocal.remove();
        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return 999;
    }
}
